<?php
global $CONFIG;
?>

<div id="header_login" style="text-align: right;">
<?php
	if (isloggedin()) {
?>
	<span>Welcome: <?php echo get_loggedin_user()->username;?></span>
	<input type="button" class="button logout" value="Logout" />
    <script type="text/javascript">
        $(document).ready(function(){
            $('#header_login .logout').click(function(){
                location.href = "<?php echo $CONFIG->getLocalhostUrl();?>/logout";
            });
        });
    </script>
<?php
	} else {
?>
	<form id="signin_form" action="signin" method="post" onsubmit="return false;">
	Username:<input type="text" class="input" name="username" size="20" value="demo" />
	Password:<input type="password" class="input" size="20" name="password" value='demo'/>&nbsp;
	<input type="submit" align="middle" class="submit" name="login_submit" value="Login">
	&nbsp;
	<a href='#'>Register</a>
	 |
	<a href='#'>Forget?</a>
	</form>
    <script type="text/javascript">
        $(document).ready(function(){
            $("form#signin_form").submit(function(){
                console.log('login start...');
                $.post($(this).attr('action'), $(this).serialize(), function(data){
                    if (data.result) {
                        $('#header_login').replaceWith(data.content);
                    } else {
                        alert("Login fail")
                    }
                },'json');
                return false;
            });
        });
    </script>
<?php
	}
?>
</div>
<?php
include "cv_block.php";
?>